package com.example.demo03_mvm.view;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.demo03_mvm.R;
import com.example.demo03_mvm.adapter.KfAdapter;
import com.example.demo03_mvm.databinding.ActivityKfactivityBinding;
import com.example.demo03_mvm.db.KfEntity;
import com.example.demo03_mvm.viewmodel.KFViewModel;

@Route(path = "/app/KFActivity")
public class KFActivity extends BaseActivity<KFViewModel,ActivityKfactivityBinding> {
    @Autowired
    int gid;
    RecyclerView rv;
    boolean flag=false;
    @Override
    protected int inflateLayout() {
        return R.layout.activity_kfactivity;
    }

    @Override
    protected void initView() {
        ARouter.getInstance().inject(this);
        rv=db.rv;
    }

    @Override
    protected void initData() {
        KfAdapter kfAdapter = new KfAdapter();
        rv.setAdapter(kfAdapter);
        rv.setLayoutManager(new LinearLayoutManager(this));
        vm.getMsg(kfAdapter,gid);

        db.tvSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String s = db.etMsg.getText().toString();
                KfEntity kfEntity = new KfEntity(s, 1, gid);
                vm.sendMsg(kfEntity,flag);
                db.etMsg.setText("");
            }
        });

        db.change.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               //true人工
                flag=true;
                kfAdapter.getData().add(new KfEntity("已为您分配0886号客服为您服务，请稍后……",0,gid));
                kfAdapter.notifyDataSetChanged();
            }
        });
    }
}